<?php
namespace App\Http\Controllers\Admin;
use App\Models\Car;
use App\Models\Config;
use Illuminate\Http\Request;

class ConfigController extends BaseController
{

    public function site() {
        $info = Config::where('key', Config::SITE_KEY)->value('value');
        $info = json_decode($info, true);
        $info['appoint_basic'] = json_decode($info['appoint_basic'], true);
        $info['load_basic'] = json_decode($info['load_basic'], true);
        return $this->success($info);
    }

    /**
     * 修改
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function store(Request $request) {
        $this->validate($request, [
            'qiao_num' => 'required',
            'wait_num' => 'required',
            'sign_in_distance' => 'required'
        ]);
        $input = $request->input();
        $model = Config::where('key',Config::SITE_KEY )->first();
        $model->value = $input;//json_encode($input, JSON_UNESCAPED_UNICODE);
        $model->save();

        //同时要修改将车计划导入
//        $cur_date = Car::where('date', '>', date('Y-m-d H:i:s'))->value('cur_date');
//        if ($cur_date) {
//            Car::where('date', '>', date('Y-m-d H:i:s'))->update([
//                'date' => $cur_date . " " . $input['start_time']
//            ]);
//        }

        $cache_key = 'config_key_' . date('Y-m-d');
        \Cache::forget($cache_key);

        $cache_key = 'config_key_' . date("Y-m-d",strtotime("+1 day"));
        \Cache::forget($cache_key);

        \Cache::forget('notify_start_time');

        \Cache::forget('sign_in_clock');

        return $this->success([]);
    }

}

